home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
shazam.exe
/
GSTRING.IMP
< prev
next >
Wrap
Text File
|
1992-09-01
|
37KB
|
1,033 lines
{*******************************************************************
GSTRING.IMP
*******************************************************************}
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*** TEXT ***
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{===================================================================
BLANK - TRUE if blank or WhiteSpace
===================================================================}
function IsBlank ( S : string ) : boolean ;
var
x : byte ;
begin
IsBlank := FALSE ;
for x := 1 to length ( S ) do
if S [ x ] <> #32 then EXIT ;
IsBlank := TRUE ;
end ;
{===================================================================
DUP - Return string of length "Len" of char "Ch"
===================================================================}
function StrDup ( Ch : char ; len : byte ) : string ;
var
S : string ;
begin
FillChar ( S [ 1 ] , 255 , Ch ) ;
S [ 0 ] := chr ( len ) ;
StrDup := S ;
end ;
{===================================================================
CASE (to upper)
===================================================================}
function StrUpCase ( S : string ) : string ;
var
b : byte ;
begin
for b := 1 to length ( S ) do
S [ b ] := UpCase ( S [ b ] ) ;
StrUpCase := S ;
end ;
{===================================================================
CASE (to lower)
===================================================================}
function LoCase ( Ch : char ) : char ;
begin
if Ch in [ 'A'..'Z' ] then
LoCase := Chr ( Ord ( Ch ) + 32 )
else
LoCase := Ch ;
end ;
{===================================================================
CASE (to lower)
===================================================================}
function StrLoCase ( S : string ) : string ;
var
x : byte ;
begin
for x := 1 to length ( S ) do
S [ x ] := LoCase ( S [ x ] ) ;
StrLoCase := S ;
end ;
{===================================================================
CAPITALS - 1st letter only
===================================================================}
function Capitalize ( S : string ) : string ;
var
x : byte ;
begin
Capitalize := S ;
for x := 1 to length ( S ) do
if S [ x ] in [ 'a'..'z' , 'A'..'Z' ] then
begin
S [ x ] := UpCase ( S [ x ] ) ;
Capitalize := S ;
EXIT ;
end ;
end ;
{===================================================================
CAPITAL - all words (after each non-alpha)
===================================================================}
function InitialCaps ( S : string ) : string ;
var
DoCap : boolean ;
x : byte ;
begin
DoCap := S [ 1 ] in [ 'a'..'z' , 'A'..'Z' ] ;
for x := 1 to length ( S ) do
begin
if DoCap then
begin
S [ x ] := UpCase ( S [ x ] ) ;
DoCap := FALSE ;
end ;
if not ( S [ x ] in [ 'a'..'z' , 'A'..'Z' ] ) then
DoCap := TRUE ;
end ;
InitialCaps := S ;
end ;
{===================================================================
PAD - increase to length "Len" with leading chars
===================================================================}
function PadLeft ( S : string ; Ch : char ; Len : byte ) : string ;
begin
while length ( S ) < len do
S := Ch + S ;
PadLeft := S ;
end ;
{===================================================================
PAD - increase to length "Len" with trailing chars
===================================================================}
function PadRight ( S : string ; Ch : char ; Len : byte ) : string ;
begin
while length ( S ) < len do
S := S + Ch ;
PadRight := S ;
end ;
{===================================================================
PUT - add leading chars
===================================================================}
function PutLeft ( S : string ; Ch : char ; Count : byte ) : string ;
begin
PutLeft := StrDup ( Ch , Count ) + S ;
end ;
{===================================================================
PUT - add trailing chars
===================================================================}
function PutRight ( S : string ; Ch : char ; Count : byte ) : string ;
begin
PutRight := S + StrDup ( Ch , Count ) ;
end ;
{===================================================================
COPY - Start to Stop, versus Start & Quantity
NOTE: Returns blank on invalid index
===================================================================}
function CopyPos ( S : string ; Start , Stop : integer ) : string ;
begin
CopyPos := '' ;
if Stop >= Start then
if Start > 0 then
CopyPos := Copy ( S ,
Start ,
Stop - Start + 1 ) ;
end ;
{===================================================================
DELETE - Start to Stop, versus Start & Quantity
NOTE: Return original on invalid index
===================================================================}
function DeletePos ( S : string ; Start , Stop : integer ) : string ;
begin
if Stop >= Start then
if Start > 0 then
delete ( S , Start , Stop - Start + 1 ) ;
DeletePos := S ;
end ;
{===================================================================
TRUNCATE - Delete from Index to end of string
===================================================================}
function Truncate ( Source : string ; Index : byte ) : string ;
begin
Truncate := DeletePos ( Source ,
Index ,
length ( Source ) ) ;
end ;
{===================================================================
MATCH - return position, ignore case
===================================================================}
function Match ( SubStr , Target : string ) : integer ;
begin
if length ( SubStr ) > 0 then
Match := pos ( StrUpCase ( SubStr ) ,
StrUpCase ( Target ) )
else
Match := 0 ;
end ;
{===================================================================
EXIST - if "SubStr" in "Target"; ignores case
===================================================================}
function StrExist ( SubStr , Target : string ) : boolean ;
begin
StrExist := Match ( SubStr , Target ) > 0 ;
end ;
{===================================================================
COUNT - number of occurances
===================================================================}
function StrCount ( SubStr , S : string ) : integer ;
var
x : integer ;
Index : integer ;
begin
x := 0 ;
while TRUE do
begin
Index := Match ( SubStr , S ) ;
if Index = 0 then
begin
StrCount := x ;
EXIT ;
end ;
inc ( x ) ;
delete ( S , Index , Length ( SubStr ) ) ;
end ;
end ;
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TRIM
||||||||||